function UserLogin(cfg){
	this.username = $('#'+cfg.name);
	this.password = $('#'+cfg.password);
	this.actionBtn = $('#'+cfg.actionBtn);
	this.init(cfg);
}
UserLogin.prototype = (function(){
	return {
		init:function(cfg){
			_self = this;
			if(cfg.tp == 'login') {
				_self.actionBtn.click(function(){
					_self.login();
				});
			}
			if(cfg.tp == 'reg') {
				_self.repassword = $('#'+cfg.repwd);
				_self.actionBtn.click(function(){
					_self.reg();
				});
			}
		},
		login:function(){
			_self = this;
			$.ajax({
				url:path+'/user/login',
				data:{uname:_self.username.val(), pwd:_self.password.val()},
				type:'POST',
				dataType:'json',
				success:function(json){
					switch(json.status) {
                        case 0:
                            InfoPanel.show('登录成功','i');
                            //$.cookie('uid', json.uid, {path:'/tutor',domain:'localhost'});
                            //$.cookie('username', json.username, {path:'/tutor',domain:'localhost'});
                            $.cookie('uid', json.uid, {path:'/'});
                            $.cookie('username', json.username, {path:'/'});
                            break;
                        case -1:
                            InfoPanel.show('用户名不存在','e');
                            break;
                        case -2:
                            InfoPanel.show('密码错误','e');
                            break;
                    }
				}
			});
		},
		reg:function(){
			_self = this;
			if(_self.password.val() != _self.repassword.val()) {
				alert('密码不一致');
				return;
			}
			$.ajax({
				url:path+'/user/register',
				data:{uname:_self.username.val(), pwd:_self.password.val()},
				type:'POST',
				dataType:'json',
				success:function(json){
					
				}
			});
		}
	};
})();
